/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kasgroup2;

import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author beha
 */
public class UIConferenceDetailsFrame extends javax.swing.JFrame {

    private Activity selActivity = null;
    private Hotel selHotel = null;
    private Speaker selSpeaker = null;
    private Subject selSubject = null;
    private Conference conference = null;
    private ArrayList<Speaker> speakerList = null;
    private ArrayList<Hotel> hotelList = null;
    private ArrayList<Activity> activityList = null;
    private TableManager tmSpeakers = null;
    private TableManager tmHotels = null;
    private TableManager tmActivities = null;
    private TableManager tmParticipants = null;
    private boolean isLoaded = false;

    
    /**
     * Creates new form UIConferenceDetailsFrame
     */
    public UIConferenceDetailsFrame() {
        initComponents();
    }
    
    public UIConferenceDetailsFrame(String p_ConferenceName) {
        this();
        activityList = new ArrayList<Activity>();
        tmSpeakers = new TableManager(this.tblSpeakers);
        tmActivities = new TableManager(this.tblActivities);
        tmParticipants = new TableManager(this.tblParticipants);
        tmHotels = new TableManager(this.tblHotels);
        loadConferenceDetails(p_ConferenceName);
        speakerList = conference.getSpeakerList();
        hotelList = conference.getHotelList();
        activityList = conference.getActivityList();
        setConferenceDescription("");
        reloadAvailableSpeakers();
        
        reloadConferenceSpeakersTable();
        reloadConferenceHotelsTable();
        reloadConferenceActivitiesTable();
        reloadConferenceParticipantsTable();
        isLoaded = true;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        txtPlace = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescription = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblSpeakers = new javax.swing.JTable();
        cmbAvailableSpeakers = new javax.swing.JComboBox();
        btnAddSpeaker = new javax.swing.JButton();
        btnDeleteSpeaker = new javax.swing.JButton();
        cmbAvailableSubjects = new javax.swing.JComboBox();
        lblConferenceDescription = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tblHotels = new javax.swing.JTable();
        cmbAvailableHotels = new javax.swing.JComboBox();
        btnAddHotel = new javax.swing.JButton();
        btnDeleteHotel = new javax.swing.JButton();
        pnlParticipants = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tblParticipants = new javax.swing.JTable();
        txtStart = new javax.swing.JFormattedTextField();
        txtEnd = new javax.swing.JFormattedTextField();
        btnSave = new javax.swing.JButton();
        chkIsActive = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane7 = new javax.swing.JScrollPane();
        tblActivities = new javax.swing.JTable();
        cmbAvailableActivities = new javax.swing.JComboBox();
        btnAddActivity = new javax.swing.JButton();
        btnDeleteActivity = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Conference Details"));

        jLabel1.setText("Name:");

        jLabel2.setText("Place:");

        jLabel3.setText("Description:");

        jLabel4.setText("Start:");

        jLabel5.setText("End:");

        txtName.setEditable(false);
        txtName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNameActionPerformed(evt);
            }
        });

        txtDescription.setColumns(20);
        txtDescription.setRows(4);
        jScrollPane1.setViewportView(txtDescription);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Speakers"));

        tblSpeakers.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Name", "Subject", "Description"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(tblSpeakers);

        cmbAvailableSpeakers.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbAvailableSpeakers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAvailableSpeakersActionPerformed(evt);
            }
        });
        cmbAvailableSpeakers.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cmbAvailableSpeakersFocusGained(evt);
            }
        });

        btnAddSpeaker.setText("Add");
        btnAddSpeaker.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSpeakerActionPerformed(evt);
            }
        });

        btnDeleteSpeaker.setText("Delete");
        btnDeleteSpeaker.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteSpeakerActionPerformed(evt);
            }
        });

        cmbAvailableSubjects.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbAvailableSubjects.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAvailableSubjectsActionPerformed(evt);
            }
        });

        lblConferenceDescription.setText("jLabel7");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(cmbAvailableSpeakers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(6, 6, 6)
                                .add(lblConferenceDescription)
                                .add(0, 0, Short.MAX_VALUE))
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(cmbAvailableSubjects, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(btnAddSpeaker)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(btnDeleteSpeaker)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(cmbAvailableSpeakers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(btnDeleteSpeaker)
                        .add(btnAddSpeaker)
                        .add(cmbAvailableSubjects, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblConferenceDescription)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Hotels"));

        tblHotels.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Name", "Address", "Room Count"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblHotels.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblHotelsMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tblHotels);
        tblHotels.getColumnModel().getColumn(0).setResizable(false);
        tblHotels.getColumnModel().getColumn(1).setResizable(false);
        tblHotels.getColumnModel().getColumn(2).setResizable(false);

        cmbAvailableHotels.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbAvailableHotels.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAvailableHotelsActionPerformed(evt);
            }
        });
        cmbAvailableHotels.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cmbAvailableHotelsFocusGained(evt);
            }
        });

        btnAddHotel.setText("Add");
        btnAddHotel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddHotelActionPerformed(evt);
            }
        });

        btnDeleteHotel.setText("Delete");
        btnDeleteHotel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteHotelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(cmbAvailableHotels, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnAddHotel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnDeleteHotel))
                    .add(jScrollPane5))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnAddHotel)
                    .add(btnDeleteHotel)
                    .add(cmbAvailableHotels, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        pnlParticipants.setBorder(javax.swing.BorderFactory.createTitledBorder("Participants"));

        tblParticipants.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane6.setViewportView(tblParticipants);

        org.jdesktop.layout.GroupLayout pnlParticipantsLayout = new org.jdesktop.layout.GroupLayout(pnlParticipants);
        pnlParticipants.setLayout(pnlParticipantsLayout);
        pnlParticipantsLayout.setHorizontalGroup(
            pnlParticipantsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlParticipantsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlParticipantsLayout.setVerticalGroup(
            pnlParticipantsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlParticipantsLayout.createSequentialGroup()
                .add(jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                .addContainerGap())
        );

        txtStart.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd-MM-yyyy hh:mm"))));

        txtEnd.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd-MM-yyyy hh:mm"))));

        btnSave.setText("Save & Close");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        chkIsActive.setText("is this conference active?");

        jLabel6.setText("State:");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Activities"));

        tblActivities.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Name", "From", "To", "Place", "Comment"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblActivities.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblActivitiesMouseClicked(evt);
            }
        });
        jScrollPane7.setViewportView(tblActivities);

        cmbAvailableActivities.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbAvailableActivities.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAvailableActivitiesActionPerformed(evt);
            }
        });
        cmbAvailableActivities.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cmbAvailableActivitiesFocusGained(evt);
            }
        });

        btnAddActivity.setText("Add");
        btnAddActivity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActivityActionPerformed(evt);
            }
        });

        btnDeleteActivity.setText("Delete");
        btnDeleteActivity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActivityActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(cmbAvailableActivities, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnAddActivity)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnDeleteActivity))
                    .add(jScrollPane7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jScrollPane7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnAddActivity)
                    .add(btnDeleteActivity)
                    .add(cmbAvailableActivities, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(pnlParticipants, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel3))
                        .add(14, 14, 14)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(txtName)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel2)
                            .add(jLabel6))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(txtPlace)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(chkIsActive)
                                .add(0, 0, Short.MAX_VALUE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(txtStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel5)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(txtEnd)))
                        .addContainerGap())
                    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(btnSave))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(txtPlace, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel3)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel4)
                            .add(txtStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel5)
                            .add(txtEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(chkIsActive)
                            .add(jLabel6)))
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(pnlParticipants, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnSave)
                .addContainerGap(10, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNameActionPerformed
        
    }//GEN-LAST:event_txtNameActionPerformed

    private void tblHotelsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblHotelsMouseClicked

   }//GEN-LAST:event_tblHotelsMouseClicked

    private void btnAddSpeakerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSpeakerActionPerformed
        int selIndex = this.cmbAvailableSpeakers.getSelectedIndex();
        if(selIndex >= 0) {
            Speaker base = KASGroup2.getCoreHandlerInstance().getSpeaker(selIndex);
            Speaker newSpeaker = new Speaker(base.getName());
            Subject subject = base.getSubject(this.cmbAvailableSubjects.getSelectedIndex());
            if(subject != null) {
                newSpeaker.addSubject(subject);
                //conference.addPerson(newSpeaker);
                tmSpeakers.addRow(new Object[] { base.getName(), subject.getName(), subject.getDescription() });
            }
            else {
                CoreHandler.MessageBox(this, "No subject", "This speaker has yet no subjects attached!");
            }
            /*for(Subject subject : speaker.getSubjectList()) {
                System.out.println("speaker: " + speaker.getName() + " - subject: " + subject.getName());
            }*/
            //conference.addPerson(speaker);
        }
        //Subject subject = speaker.getSubject(null)
        //
    }//GEN-LAST:event_btnAddSpeakerActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        KASGroup2.getCoreHandlerInstance().editConference(
                this.txtName.getText(),
                this.txtDescription.getText(),
                this.txtPlace.getText(),
                this.txtStart.getText(),
                this.txtEnd.getText(),
                this.chkIsActive.isSelected(),
                this.speakerList,
                this.activityList);
        this.dispose();
    }//GEN-LAST:event_btnSaveActionPerformed

    private void cmbAvailableSpeakersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAvailableSpeakersActionPerformed
        if(isLoaded) {
            Object obj = ((JComboBox)evt.getSource()).getSelectedItem();
            Speaker speaker = KASGroup2.getCoreHandlerInstance().getSpeaker(obj);
            this.cmbAvailableSubjects.removeAllItems();
            for(Subject s : speaker.getSubjectList()) {
                this.cmbAvailableSubjects.addItem(s.getName());
            }
        }
    }//GEN-LAST:event_cmbAvailableSpeakersActionPerformed

    private void btnDeleteSpeakerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteSpeakerActionPerformed
        //this.speakerList.remove(this.tmSpeakers.getSelectedRowIndex());
        //this.tmSpeakers.removeSelectedRow();
        String speakerName = (String)tmSpeakers.getCellValueForSelectedRow(0);
        Speaker speaker = KASGroup2.getCoreHandlerInstance().getSpeaker(speakerName);
        String subjectName = (String)tmSpeakers.getCellValueForSelectedRow(1);
        speaker.removeSubject(subjectName);
        //if(conference.removeSpeakerSubject(speakerName, subjectName)) {
            reloadConferenceSpeakersTable();
        //}
    }//GEN-LAST:event_btnDeleteSpeakerActionPerformed

    private void cmbAvailableSpeakersFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbAvailableSpeakersFocusGained
        //reloadAvailableSpeakers();
    }//GEN-LAST:event_cmbAvailableSpeakersFocusGained

    private void tblActivitiesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblActivitiesMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_tblActivitiesMouseClicked

    private void cmbAvailableHotelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAvailableHotelsActionPerformed
        selHotel = KASGroup2.getCoreHandlerInstance().getHotel(((JComboBox)evt.getSource()).getSelectedItem());
        reloadConferenceHotelsTable();
    }//GEN-LAST:event_cmbAvailableHotelsActionPerformed

    private void cmbAvailableHotelsFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbAvailableHotelsFocusGained
        this.reloadAvailableHotels();
    }//GEN-LAST:event_cmbAvailableHotelsFocusGained

    private void btnAddHotelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddHotelActionPerformed
        this.hotelList.add(selHotel);
        this.tmHotels.addRow(new Object[] { selHotel.getName(), selHotel.getAddress(), selHotel.getRoomCount() });
    }//GEN-LAST:event_btnAddHotelActionPerformed

    private void btnDeleteHotelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteHotelActionPerformed
        this.hotelList.remove(tmHotels.getSelectedRowIndex());
        this.tmHotels.removeSelectedRow();
    }//GEN-LAST:event_btnDeleteHotelActionPerformed

    private void cmbAvailableActivitiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAvailableActivitiesActionPerformed
        selActivity = KASGroup2.getCoreHandlerInstance().getActivity(((JComboBox)evt.getSource()).getSelectedItem());
        reloadConferenceActivitiesTable();
    }//GEN-LAST:event_cmbAvailableActivitiesActionPerformed

    private void cmbAvailableActivitiesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbAvailableActivitiesFocusGained
        this.reloadAvailableActivities();
    }//GEN-LAST:event_cmbAvailableActivitiesFocusGained

    private void btnAddActivityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActivityActionPerformed
        this.activityList.add(selActivity);
        reloadConferenceActivitiesTable();
    }//GEN-LAST:event_btnAddActivityActionPerformed

    private void btnDeleteActivityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActivityActionPerformed
        this.activityList.remove(tmActivities.getSelectedRowIndex());
        tmActivities.removeSelectedRow();
    }//GEN-LAST:event_btnDeleteActivityActionPerformed

    private void cmbAvailableSubjectsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAvailableSubjectsActionPerformed
        //setConferenceDescription
    }//GEN-LAST:event_cmbAvailableSubjectsActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UIConferenceDetailsFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UIConferenceDetailsFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UIConferenceDetailsFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UIConferenceDetailsFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new UIConferenceDetailsFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddActivity;
    private javax.swing.JButton btnAddHotel;
    private javax.swing.JButton btnAddSpeaker;
    private javax.swing.JButton btnDeleteActivity;
    private javax.swing.JButton btnDeleteHotel;
    private javax.swing.JButton btnDeleteSpeaker;
    private javax.swing.JButton btnSave;
    private javax.swing.JCheckBox chkIsActive;
    private javax.swing.JComboBox cmbAvailableActivities;
    private javax.swing.JComboBox cmbAvailableHotels;
    private javax.swing.JComboBox cmbAvailableSpeakers;
    private javax.swing.JComboBox cmbAvailableSubjects;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JLabel lblConferenceDescription;
    private javax.swing.JPanel pnlParticipants;
    private javax.swing.JTable tblActivities;
    private javax.swing.JTable tblHotels;
    private javax.swing.JTable tblParticipants;
    private javax.swing.JTable tblSpeakers;
    private javax.swing.JTextArea txtDescription;
    private javax.swing.JFormattedTextField txtEnd;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPlace;
    private javax.swing.JFormattedTextField txtStart;
    // End of variables declaration//GEN-END:variables

    private void loadConferenceDetails(String p_ConferenceName) {
        
        this.conference = KASGroup2.getCoreHandlerInstance().getConference(p_ConferenceName);
        this.txtName.setText(conference.getName());
        this.txtDescription.setText(conference.getDescription());
        this.txtPlace.setText(conference.getPlace());
        this.txtStart.setText(CoreHandler.DateToString(conference.getStartTime()));
        this.txtEnd.setText(CoreHandler.DateToString(conference.getEndTime()));
        this.chkIsActive.setSelected(conference.getIsActive());
        reloadConferenceSpeakersTable();
        reloadConferenceActivitiesTable();
        reloadConferenceParticipantsTable();
    }

    private void reloadConferenceSpeakersTable() {
        tmSpeakers.clear();
        for(Speaker speaker : conference.getSpeakerList()) {
            System.out.println(speaker.getName());
            for(Subject subject : speaker.getSubjectList()) {
                tmSpeakers.addRow(new Object[] { 
                                        speaker.getName(), 
                                        subject.getName(), 
                                        subject.getDescription() 
                });
                System.out.println("\t" + subject.getName() + " - "+
                                        subject.getDescription());
            }
        }
    }

    private void reloadConferenceParticipantsTable() {
        tmParticipants.clear();
        for(Participant p : conference.getParticipantList()) {
            System.out.println(p.getName());
            tmParticipants.addRow(new Object[] { p.getName() });
        }
    }

    private void reloadConferenceActivitiesTable() {
        tmActivities.clear();
        for(Activity a : conference.getActivityList()) {
            tmActivities.addRow(new Object[] { 
                a.getName(), 
                CoreHandler.DateToString(a.getStartTime()),
                CoreHandler.DateToString(a.getEndTime()),
                a.getPlace(),
                a.getComment()
            });
        }
    }
    
    private void reloadConferenceHotelsTable() {
        tmHotels.clear();
        for(Hotel h : conference.getHotelList()) {
            this.tmHotels.addRow(new Object[] { h.getName(), h.getAddress(), h.getRoomCount() });
        }
    }

    private void reloadAvailableSpeakers() {
        this.cmbAvailableSpeakers.removeAllItems();
        for(Speaker s : KASGroup2.getCoreHandlerInstance().getSpeakerList()) {
            this.cmbAvailableSpeakers.addItem(s.getName());
        }
    }

    private void reloadAvailableHotels() {
        this.cmbAvailableHotels.removeAllItems();
        for(Hotel h : KASGroup2.getCoreHandlerInstance().getHotelList()) {
            this.cmbAvailableHotels.addItem(h.getName());
        }
    }
    
    private void reloadAvailableActivities() {
        this.cmbAvailableActivities.removeAllItems();
        for(Activity a : KASGroup2.getCoreHandlerInstance().getActivityList()) {
            this.cmbAvailableActivities.addItem(a.getName());
        }
    }

    private void setConferenceDescription(String s) {
        this.lblConferenceDescription.setText(s);
    }

}
